<?php
/**
 * php GEM Project
 * 
 * LICENSE
 * 
 * PHP System Architecture Enabling Rapid Application Deployment and Scalability
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @copyright Copyright (C) 2010 Zeletron LLC (http://zeletron.com)
 * @license http://gem.zeletron.com/license
 */

/**
 * GEM/Validate/Timezone.php
 * 
 * @author David Joly
 * @category GEM
 * @package GEM_Validate
 */

class GEM_Validate_Timezone extends Zend_Validate_Abstract 
{ 
	/**
	 * Validation failure message keys.
	 */
	const NOT_TIMEZONE = 'notTimezone'; 
    
	/**
     * Validation failure message template definition
     *
     * @var array
     */
	protected $_messageTemplates = array(self::NOT_TIMEZONE => 'Unknown timezone.'); 
    
	public function __construct()
    {}
    /**
     * This function will return false if the timezone is not found.
     * 
     * @param $value 
     * @return boolean
     * @uses DateTimeZone
     */
	public function isValid($value) 
	{ 
		$value = (string) $value; 
        $this->_setValue($value);   
        $timezones = DateTimeZone::listIdentifiers();   

        if(!in_array($value,$timezones)){
        	$this->_error(self::NOT_TIMEZONE);
        	return false;
        }
        return true;
	} 
} 